using System.Collections.Generic;
using System.Text;
using System;
using NHibernate;
using NHibernate.Cfg;
using JVLMRP;
namespace JVLMRP 
{
    class MRPSizesService 
    {
        ISession session;

        public MRPSizesService(ISession session)
        {
            this.session = session;
        }
        public MRPSizesService( )
        {
            this.session = SessionFactory.GetNewSession();
        }
        public void InsertMrpsizes(MRPSizes mrpsizesX)
        {
            ITransaction tx = session.BeginTransaction();
            session.Save(mrpsizesX);
            tx.Commit();
        }

        public void UpdateMrpsizes(MRPSizes mrpsizesX)
        {
            ITransaction tx = session.BeginTransaction();
            session.Update(mrpsizesX);
            tx.Commit();
        }

        public void DeleteMrpsizes(MRPSizes mrpsizesX)
        {
            ITransaction tx = session.BeginTransaction();
            session.Delete(mrpsizesX);
            tx.Commit();
        }

        public IList<MRPSizes> GetAllMrpsizes(Boolean evict)
        {
            IQuery query = session.CreateQuery("select from MRPSizes");
            IList<MRPSizes> list = query.List<MRPSizes>();
            if (evict)
            {
                foreach (MRPSizes s in list)
                {
                    session.Evict(s);
                }
            }
            return list;
        }

        public MRPSizes GetAllMrpsizesByID(String id,Boolean evict)
        {
            IQuery query = session.CreateQuery("select c from MRPSizes as c where c.Sizeid= :x");
            query.SetString("x", id);
            MRPSizes s = (MRPSizes)query.UniqueResult();
            if (evict)
            {
                session.Evict(s);
            }
            return s;
        }

        public IList<MRPSizes> GetMrpsizesByQuery(IQuery query,Boolean evict)
        {
            IList<MRPSizes> list = query.List<MRPSizes>();
            if (evict)
            {
                foreach (MRPSizes s in list)
                {
                    session.Evict(s);
                }
            }
            return list;
        }
    }
}
